#include <iostream>
#include <string>
#include <set>
#include <cmath>
 
// 坐标点类
struct Point
{
    double x, y;
};

struct PointCmp
{
    // 自定义比较器
    bool operator()(const Point& lhs, const Point& rhs) const
    { 
        return std::hypot(lhs.x, lhs.y) < std::hypot(rhs.x, rhs.y); 
    }
};
 
int main()
{
  // (1) 默认初始化器
  std::set<std::string> a;
  a.insert("cat");
  a.insert("dog");
  a.insert("horse");
  for(auto& str: a)
    std::cout << str << ' ';
  std::cout << '\n';
 
  // (2) 迭代器初始化器
  std::set<std::string> b(a.find("dog"), a.end());
  for(auto& str: b) std::cout << str << ' ';
  std::cout << '\n';
 
  // (3) 复制构造函数
  std::set<std::string> c(a);
  c.insert("another horse");
  for(auto& str: c) std::cout << str << ' ';
  std::cout << '\n';
 
  // (4) 移动构造函数
  std::set<std::string> d(std::move(a));
  for(auto& str: d) std::cout << str << ' ';
  std::cout << '\n';
  std::cout << "moved-from set is ";
  for(auto& str: a) std::cout << str << ' ';
  std::cout << '\n';
 
  // (5) initializer_list 构造函数
  std::multiset<std::string> e {"one", "two", "three", "five", "eight", "two"};
  for(auto& str: e) std::cout << str << ' ';
  std::cout << '\n';
 
  // 自定义比较
  std::set<Point, PointCmp> z = {{2, 5}, {3, 4}, {1, 1}};
  z.insert({1, -1}); // 这会失败，因为 1,-1 的长度等于 1,1

  for(auto& p: z)
    std::cout << '(' << p.x << ',' << p.y << ") ";
  std::cout << '\n';
}